package com.hxzy.rocketmqproduce.controller;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestTopicController {


    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping(value = "/testTopic/send")
    public String sendMsg(){

        //destination – formats: `topicName:tags`  topic名称(:路由关键字) 可以不加的
        for (int i=1;i<=10;i++) {

            if(i==8){
                this.rocketMQTemplate.syncSend("testTopic:TagA", "你好-"+i);
            }else{
                this.rocketMQTemplate.syncSend("testTopic", "你好-"+i);
            }
        }
        return "发送完成";
    }



}
